package cn.yunhe.controller;

import cn.yunhe.model.Role;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * Created by zs on 2017/12/4.
 */
@Controller
@RequestMapping("/my")
public class MyController {

    /**
     * 普通请求
     *
     * @return
     */
    @RequestMapping("/index")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }

    /**
     * 传递参数
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/index2", method = RequestMethod.GET)
    public ModelAndView index2(@RequestParam("id") Long id) {
        System.out.println("id====" + id);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }

    @RequestMapping(value = "/getRole", method = RequestMethod.GET)
    public ModelAndView getRole(@RequestParam("id") Long id) {
        Role role = new Role(1L, "lisi", "l");
        ModelAndView mv = new ModelAndView();
        mv.addObject("role", role);
        mv.setView(new MappingJackson2JsonView());  //向前台传递json数据
        return mv;

    }


}
